package com.home.truc.GUI;

import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import javax.swing.JWindow;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Color;

import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;

import com.home.Entity.Ban;
import com.home.duy.code.DAO.BanDAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.util.List;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class frmChuyenBan extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;

	/**
	 * @param owner
	 */
	public frmChuyenBan(long mBan) {
		super();
		setAlwaysOnTop(true);
		initialize();
		
		this.maBan = mBan;
		LoadData();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(486, 395);
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo(null);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	JButton btnXong = null;
	JButton btnHuy = null;
	JList listBan1 = null;
	JComboBox comboBoxBan1 = null;
	JList listBan2 = null;
	JComboBox comboBoxBan2 = null;
	JButton bLeft = null;
	JButton bLeftAll = null;
	JButton bRight = null;
	JButton bRightAll = null;
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setBorder(null);
			jContentPane.setLayout(new BorderLayout());
			
			JLabel lblChuynBn = new JLabel("CHUYỂN BÀN");
			lblChuynBn.setForeground(Color.BLUE);
			lblChuynBn.setFont(new Font("Tahoma", Font.BOLD, 20));
			lblChuynBn.setHorizontalAlignment(SwingConstants.CENTER);
			jContentPane.add(lblChuynBn, BorderLayout.NORTH);
			
			JPanel panel = new JPanel();
			jContentPane.add(panel, BorderLayout.SOUTH);
			
			btnXong = new JButton("Xong");
			btnXong.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					setVisible(false);
				}
			});
			panel.add(btnXong);
			
			btnHuy = new JButton("Huỷ");
			btnHuy.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			panel.add(btnHuy);
			
			JPanel panel_1 = new JPanel();
			jContentPane.add(panel_1, BorderLayout.CENTER);
			panel_1.setLayout(null);
			
			JPanel panel_2 = new JPanel();
			panel_2.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panel_2.setBounds(10, 11, 173, 285);
			panel_1.add(panel_2);
			panel_2.setLayout(new BorderLayout(0, 0));
			
			JScrollPane scrollPane = new JScrollPane();
			panel_2.add(scrollPane, BorderLayout.CENTER);
			
			listBan1 = new JList();
			scrollPane.setViewportView(listBan1);
			
			comboBoxBan1 = new JComboBox();
			comboBoxBan1.addActionListener(new ActionListener() {
			      public void actionPerformed(ActionEvent e) {
			    	  ChonItemCB1(comboBoxBan1.getSelectedIndex());
			        }
			      });
			scrollPane.setColumnHeaderView(comboBoxBan1);
			
			JPanel panel_3 = new JPanel();
			panel_3.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panel_3.setBounds(277, 11, 173, 285);
			panel_1.add(panel_3);
			panel_3.setLayout(new BorderLayout(0, 0));
			
			JScrollPane scrollPane_1 = new JScrollPane();
			panel_3.add(scrollPane_1, BorderLayout.CENTER);
			
			listBan2 = new JList();
			scrollPane_1.setViewportView(listBan2);
			
			comboBoxBan2 = new JComboBox();
			comboBoxBan2.addActionListener(new ActionListener() {
			      public void actionPerformed(ActionEvent e) {
			    	  ChonItemCB2(comboBoxBan2.getSelectedIndex());
			        }
			      });
			scrollPane_1.setColumnHeaderView(comboBoxBan2);
			
			bLeft = new JButton(">");
			bLeft.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			bLeft.setFont(new Font("Tahoma", Font.BOLD, 11));
			bLeft.setBounds(198, 64, 61, 23);
			panel_1.add(bLeft);
			
			bLeftAll = new JButton(">>");
			bLeftAll.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			bLeftAll.setFont(new Font("Tahoma", Font.BOLD, 11));
			bLeftAll.setBounds(199, 98, 61, 23);
			panel_1.add(bLeftAll);
			
			bRight = new JButton("<");
			bRight.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			bRight.setFont(new Font("Tahoma", Font.BOLD, 11));
			bRight.setBounds(199, 179, 61, 23);
			panel_1.add(bRight);
			
			bRightAll = new JButton("<<");
			bRightAll.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
				}
			});
			bRightAll.setFont(new Font("Tahoma", Font.BOLD, 11));
			bRightAll.setBounds(199, 213, 61, 23);
			panel_1.add(bRightAll);
		}
		return jContentPane;
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	private long maBan = 0;
	List<Ban> LValue = null;
	private boolean loading = false;
	private boolean canShow = true;
	public boolean CanShow()
	{
		return this.canShow;
	}
	public void LoadData()
	{
		loading = true;
		try {
			BanDAO daoBan = new BanDAO();
			LValue = daoBan.TimDSBanSuDung();
			
			//kiem tra dieu kien hien thi form
			if(LValue.size() < 2)
			{
				JOptionPane.showMessageDialog(this, "Không thể chuyển bàn vì số lượng bàn quá ít!!!");
				this.canShow = false;
				return;
			}
			for(Ban b : LValue)
			{
				this.comboBoxBan1.addItem(b.getTen());
				this.comboBoxBan2.addItem(b.getTen());
			}
			
			this.comboBoxBan1.setSelectedIndex(0);
			this.comboBoxBan2.setSelectedIndex(1);
		} catch (Exception e) {
			JOptionPane.showInputDialog(e.toString());
		}
		loading = false;
	}
	public void ChonItemCB1(int index)
	{
		
	}
	public void ChonItemCB2(int index)
	{
		
	}
	public void SetValue(long ban)
	{
		this.maBan = ban;
	}
}
